package entity;

public class Printer {
    private final BlackCartridge blackCartridge;
     final ColorCartridge colorCartridge;

    // 构造方法，通过构造注入获取墨盒实例
    public Printer(BlackCartridge blackCartridge, ColorCartridge colorCartridge) {
        this.blackCartridge = blackCartridge;
        this.colorCartridge = colorCartridge;
    }

    // 根据传入的墨盒类型进行打印操作
    public void print(String text, String cartridgeType) {
        if ("black".equals(cartridgeType)) {
            System.out.println(blackCartridge.printText(text));
        } else if ("color".equals(cartridgeType)) {
            System.out.println(colorCartridge.printText(text));
        } else {
            System.out.println("无效的墨盒类型");
        }
    }
}
